package com.gxuwz.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.gxuwz.entity.User;

/**
 * 
 * ClassName: SessionUtils
 * @Description: 获取session工具类
 * @author 刘玉霜
 * @date 2017年10月27日
 */
public class SessionUtils {

	public static HttpSession getSession() { 
	    HttpSession session = null; 
	    try { 
	        session = getRequest().getSession(); 
	    } catch (Exception e) {} 
	        return session; 
	}
	
	public static User getLoginUser(){
		return (User) getSession().getAttribute("loginUser");
	}
	
	public static HttpServletRequest getRequest() { 
	    ServletRequestAttributes attrs =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 
	    return attrs.getRequest(); 
	}
	
}
